$=jQuery;(function($){var a={},c="doTimeout",d=Array.prototype.slice;$[c]=function(){return b.apply(window,[0].concat(d.call(arguments)))};$.fn[c]=function(){var f=d.call(arguments),e=b.apply(this,[c+f[0]].concat(f));return typeof f[0]==="number"||typeof f[1]==="number"?this:e};function b(l){var m=this,h,k={},g=l?$.fn:$,n=arguments,i=4,f=n[1],j=n[2],p=n[3];if(typeof f!=="string"){i--;f=l=0;j=n[1];p=n[2]}if(l){h=m.eq(0);h.data(l,k=h.data(l)||{})}else{if(f){k=a[f]||(a[f]={})}}k.id&&clearTimeout(k.id);delete k.id;function e(){if(l){h.removeData(l)}else{if(f){delete a[f]}}}function o(){k.id=setTimeout(function(){k.fn()},j)}if(p){k.fn=function(q){if(typeof p==="string"){p=g[p]}p.apply(m,d.call(n,i))===true&&!q?o():e()};o()}else{if(k.fn){j===undefined?e():k.fn(j===false);return true}else{e()}}}})(jQuery);
var wp_octoms = {
	toolbox: {
		colored: function(h){
			
		},
		getHashValue: function() 
		{
			var arr = window.location.hash.split("#");
			var hasValue = arr[1];
			if (typeof hasValue == "undefined") 
			{
				return false;
			}
			var hashLen = hasValue.indexOf("?");
			if(hashLen>0)
			{
				hasValue = hasValue.substring(0,hashLen);
			}
			return hasValue;
		},
		onHashChange: function(event) {
			var lastHash = wp_octoms.toolbox.getHashValue();
			event(lastHash);
			(function watchHash() 
			{
				var hash = wp_octoms.toolbox.getHashValue();
				if (hash !== lastHash) 
				{
					event(hash); lastHash = hash;
				}
				var t = setTimeout(watchHash, 100);
			})();
		},
		redirect: function(h,to) {
			window.location.href = (typeof to != 'string')?window.location.href:to;
		},
		refresh: function() {
			location.reload();
		},
		update: function(h,c){
			$.each(c,function(k,v){
				k = k.replace(/(\[|\])/ig, "\\\$1");
				$('[name='+k+']').val(v);
			});
		},
		wp_replace: function(h,c){
			$('.admin-right').fadeOut(function(){
				$(this).html(c);
				$(this).fadeIn();
				wp_octoms.xform().shortkeys().custom_uploads();
			});
		},
		wp_ajax: function(h,c){
			wp_octoms.xform(c, $('.admin-right'));
		},
		mark: function(h,c){
			if(typeof c.id != 'undefined')
			{
				$('#'+c.id).css('background','red');
			}
		},
		form_validate: function(h,c){
			$('form.x span[id^=rule-]').html('');
			$.each(c,function(k,v){
				$('#rule-'+k).html(v[0]);
			});
		}
	},
	hood: 
	{
		init: function(){
			$(window).resize(function(){
				wp_octoms.hood.refresh();
			});
			setInterval(function(){
				var folded = $('body').hasClass('folded');
				if((folded && !wp_octoms.hood.folded) || (!folded && wp_octoms.hood.folded))
				{
					wp_octoms.hood.folded = folded;
					wp_octoms.hood.refresh();
				}
			},200);
			wp_octoms.hood.refresh();
			$('#the-hood .btn').live('click',function(){
				wp_octoms.hood.visible = !wp_octoms.hood.visible;
				if(wp_octoms.hood.visible)
				{
					$('#the-hood iframe').css('display','block');
					$('#the-hood .btn').addClass('visible');
					$('#the-hood').animate(wp_octoms.hood.refresh(true),1000);
				}
				else
				{
					$('#the-hood iframe').css('display','none');
					$('#the-hood .btn').removeClass('visible');
					$('#the-hood').animate(wp_octoms.hood.refresh(true),800);
				}
			});
			return wp_octoms.hood;
		},
		refresh: function(r){
			var wpbody = $('#wpbody');
			var wpadminbar = $('#wpadminbar');
			var width = wpbody.outerWidth()+19;
			var height = wp_octoms.hood.visible?($(window).height()-$('#wpadminbar').outerHeight()-40):0;
			if(typeof r != 'undefined' && r == true)
			{
				return {width:width,height:height};
			}
			
			$('#the-hood').css({
				width:width,
				height:height
			});
			return wp_octoms.hood;
		},
		wp_folded:true,
		visible:false
	},
	shortkeys_set: {},
	shortkeys: function()
	{
		var actions = {};
		$.each($('[key]'),function(k,v){
			code = $(this).attr('key').toUpperCase().charCodeAt(0);
			if(typeof wp_octoms.shortkeys_set[code] == 'undefined')
			{
				actions[code] = $(this);
				wp_octoms.shortkeys_set[code] = $(this);
			}
			
		});
		$(document).keydown(function(e){
			if(e.ctrlKey && typeof actions[e.keyCode] != 'undefined')
			{
				e.stopPropagation();
				e.preventDefault();
				$(actions[e.keyCode]).click();
			}
		});
		
		return wp_octoms;
	},
	init:function(){
		document.write("<div id='loadingPage'><div>Loading...</div></div>");
		$(document).ready(function(){
			wp_octoms.xform().help().shortkeys().custom_uploads().hood.init();
			$('#loadingPage').fadeOut(600,function(){$(this).remove();});
		});
	},
	custom_uploads: function(){
		$('.file_container > span').css('z-index',2).click(function(e){
			$(this).siblings('input[type=file]').click();
		});
		var offset = $('.file_container').offset();
		var file = $('.file_container > input[type=file]');
		$('.file_container > span').mousemove(function(e){
			$(this).siblings('input[type=file]').css({
				top: e.pageY - offset.top - file.outerHeight()/2,
				left: e.pageX - offset.left - file.outerWidth()/2,
				width: 'auto',
				height: 'auto',
				position: 'absolute',
				margin: '0'
			});
		}).mouseout(function(e){
			$(this).children('input[type=file]').css({
				position: 'relative',
				width: '100%',
				height: '100%'
			});
		});
		$('.file_container > input[type=file]').change(function(e){
			var filename = $(this).val();
			filename = filename.substring(filename.lastIndexOf("\\")+1);

			$(this).siblings('span.filename').html(filename).css('marginRight','10px');
		});
		
		return wp_octoms;
	},
	save_tinymce: function()
	{
		if(typeof tinyMCE != 'undefined')
		{
			$.each($('.wp-editor-area'),function(k,v){
				if(typeof tinyMCE.get($(v).attr('id')) != 'undefined')
				{
					tinyMCE.get($(v).attr('id')).save();
				}
			});
		}
	},
	xform:function(customData,customHolder){
		// Any non-AJAX form
		$('form').not('.x').submit(function(){
			wp_octoms.alert('Loading...','loading');
			wp_octoms.save_tinymce();
			return true;
		});
		
		// Set the AJAX success function
		var successFnc = function(d,s,j,h){
			try
			{
				if(typeof h == 'undefined') h = (typeof customHolder != 'undefined'?customHolder:'');
				d = $.parseJSON(d);
				(typeof d._status_ != 'undefined')?wp_octoms.alert(d._status_[0],d._status_[1]):(typeof d.octoms_error != 'undefined' || typeof d.octoms_help != 'undefined'?wp_octoms.alert('Error.',false):wp_octoms.alert('Done.',true));
				(typeof d._filters_ != 'undefined')?$.each(d._filters_,function(k,v){(typeof wp_octoms.toolbox[v] == 'function')?wp_octoms.toolbox[v](h,(typeof d._content_ !='undefined'?d._content_:null)):null;}):null;
				if(typeof d.octoms_error != 'undefined')
				{
					if(typeof d.octoms_error.e != 'undefined' && d.octoms_error.e != null)
					{
						wp_octoms.box('OctoMS PHP Framework <span style="color:red">Error</span>','<div>'+$.parseJSON(d.octoms_error.e)+'</div>');
					}
					if(typeof d.octoms_error.x != 'undefined' && d.octoms_error.x != null)
					{
						wp_octoms.box('OctoMS PHP Framework <span style="color:red">Exception</span>','<div>'+$.parseJSON(d.octoms_error.x)+'</div>');
					}
				}
				if(typeof d.octoms_help != 'undefined')
				{
					if(typeof d.octoms_help.c != 'undefined' && d.octoms_help.c != null)
					{
						wp_octoms.box('OctoMS PHP Framework <span style="color:blue">Variable export</span>','<div>'+$.parseJSON(d.octoms_help.c)+'</div><br/><h2>Please remove the help() function call from your script.</h2>');
					}
					else if(typeof d.octoms_help.s != 'undefined' && d.octoms_help.s != null)
					{
						wp_octoms.box('OctoMS PHP Framework <span style="color:blue">Wizard search</span>','<div>'+d.octoms_help.s+'</div><br/><h2>Please remove the help() function call from your script.</h2>');
					}
				}
			}
			catch(err)
			{
				//wp_octoms.toolbox.refresh();
			}
			
			// Using Recaptcha?
			if(typeof Recaptcha != "undefined") Recaptcha.reload();
		};
		
		// Set the AJAX error function
		var errorFnc = function(d,s,j){
//			wp_octoms.toolbox.refresh();
		};
		
		// Send custom data?
		if(typeof customData == "object")
		{
			// Show the loading alert
			wp_octoms.alert('Loading...','loading');
			
			// Save tinyMCE
			wp_octoms.save_tinymce();
			
			// AJAX response expected
			customData["#*#"] = true;
			// Set the AJAX settings
			var ajaxSettings = 
			{
				type: 'post',
				data: customData,
				cache: false,
				async: true,
				dataType: 'text',
				success: successFnc,
				error: errorFnc
			};
			
			// Get the ajax response
			$.ajax(ajaxSettings);
			
			// Stop here
			return wp_octoms;
		}
		
		// Proccess all AJAX forms
		$.each($('form.x'),function(k,v){
			if($(this).attr('rel') != 'plain' && typeof $(this).data('events') == 'undefined')
			{
				$(this).submit(function(){
					// Show the loading alert
					wp_octoms.alert('Loading...','loading');
					
					// Get the form element
					var h = $(this);
					
					// Initiate the form variable
					var form = {}; 
					
					// Save tinyMCE
					wp_octoms.save_tinymce();
					
					// Get all the fields
					$.each(h.find('[name]'),function(){
						if($(this).attr('type')=='checkbox'||$(this).attr('type')=='radio')
						{
							if($(this).attr('value').lenght == 0)
							{
								form[$(this).attr('name')] = $(this).attr('checked')=='checked';
							}
							else
							{
								if($(this).attr('checked')=='checked')
								{
									form[$(this).attr('name')] = $(this).val();
								}
							}
						}
						else
						{
							form[$(this).attr('name')] = $(this).val();
						}
					});
					
					// AJAX response expected
					form["#*#"] = true;
					
					// Extra data
					if(typeof $(this).data('*') != 'undefined') 
					{
						$.each($(this).data('*'),function(k,v){form[k]=v;});
					}
					
					// Set the AJAX settings
					var ajaxSettings = 
					{
						type: 'post',
						data: form,
						cache: false,
						async: true,
						dataType: 'text',
						success: function(d,s,j){successFnc(d,s,j,h);},
						error: errorFnc
					};
					
					// Set the action
					if(typeof $(v).attr('action') != 'undefined' && $(v).attr('action').length>0)
					{
						ajaxSettings.url = $(v).attr('action');
					}
					
					// Get the ajax response
					$.ajax(ajaxSettings);
					
					// Always return false
					return false;
				});
			}
		});
		
		// Create the confirmation boxes
		wp_octoms.confirm();
		
		// Return this
		return wp_octoms;
	},
	yform: function(d){
		try
		{
			var h = $('form').not('.x');
			(typeof d._status_ != 'undefined')?wp_octoms.alert(d._status_[0],d._status_[1]):(typeof d.octoms_error != 'undefined' || typeof d.octoms_help != 'undefined'?wp_octoms.alert('Error.',false):wp_octoms.alert('Done.',true));
			(typeof d._filters_ != 'undefined')?$.each(d._filters_,function(k,v){(typeof wp_octoms.toolbox[v] == 'function')?wp_octoms.toolbox[v](h,(typeof d._content_ !='undefined'?d._content_:null)):null;}):null;
			if(typeof d.octoms_error != 'undefined')
			{
				if(typeof d.octoms_error.e != 'undefined' && d.octoms_error.e != null)
				{
					wp_octoms.box('OctoMS PHP Framework <span style="color:red">Error</span>','<div>'+$.parseJSON(d.octoms_error.e)+'</div>');
				}
				if(typeof d.octoms_error.x != 'undefined' && d.octoms_error.x != null)
				{
					wp_octoms.box('OctoMS PHP Framework <span style="color:red">Exception</span>','<div>'+$.parseJSON(d.octoms_error.x)+'</div>');
				}
			}
			if(typeof d.octoms_help != 'undefined')
			{
				if(typeof d.octoms_help.c != 'undefined' && d.octoms_help.c != null)
				{
					wp_octoms.box('OctoMS PHP Framework <span style="color:blue">Variable export</span>','<div>'+$.parseJSON(d.octoms_help.c)+'</div><br/><h2>Please remove the help() function call from your script.</h2>');
				}
				else if(typeof d.octoms_help.s != 'undefined' && d.octoms_help.s != null)
				{
					wp_octoms.box('OctoMS PHP Framework <span style="color:blue">Wizard search</span>','<div>'+d.octoms_help.s+'</div><br/><h2>Please remove the help() function call from your script.</h2>');
				}
			}
		}
		catch(err)
		{
		}
		
		return wp_octoms;
	},
	alert:function(text,s,d,t){
		if(typeof text=='undefined' || typeof text != 'string') text = text.toString();
		status = (typeof s=='undefined')?'success':(s==true?'success':(s==false?'error':s));
		duration = (typeof d=='undefined')?300:d;
		timeout = (typeof t=='undefined')?8000:t;
		if($('#notif').length == 0) $('body').append('<div id="notif"></div>');
		var notif = $('#notif').css('display','none').removeClass().addClass('notif_'+status).html(text);
		var hide = function(){(status=='loading')?notif.css('display','none'):notif.fadeOut(duration);};
		(status=='loading')?notif.css('display','block'):notif.fadeIn(duration);
		$.alertTimeout && clearTimeout($.alertTimeout);
		$.alertTimeout = setTimeout(hide,timeout);
		$('#notif').hover(
				function(){clearTimeout($.alertTimeout);},
				function(){clearTimeout($.alertTimeout);$.alertTimeout = setTimeout(hide,500);}
		);
	},
	box:function(title,content,actions,event,holder){
		if(typeof actions == 'undefined') actions = {"ok":function(e,h){return true;},"cancel":function(e,h){return false;}};
		if(typeof content == 'undefined') content = "";
		if(typeof title == 'undefined') title = "WP-OctoMS";
		buttons = '';
		$.each(actions,function(k,v){t = k.charAt(0).toUpperCase();t = t + k.substr(1);buttons += '<div class="action unselectable" rel="'+k+'">'+t+'</div>';});
		$('body').prepend('<div class="fervbox"><div><div class="title unselectable">'+title+'<div class="action close">x</div></div><div class="content">'+content+'</div>'+buttons+'</div></div>');
		var fervbox = $('body :first').fadeIn(600);	
		$('.action',fervbox).click(function(){
			if(typeof actions[$(this).attr('rel')] != 'undefined')
			{
				actions[$(this).attr('rel')](event,holder);
			}
			fervbox.fadeOut(500,function(){fervbox.remove();});
		});
		$(document).keydown(function(e){if(e.keyCode == 27) {fervbox.fadeOut(500,function(){fervbox.remove();});}});
	},
	confirm:function(){		
		var handler = function(e){
			var v = $(this);
			e.stopImmediatePropagation();
			e.stopPropagation();
			e.preventDefault();
			wp_octoms.box(
				(typeof $(v).attr('title')=='undefined')?$(v).data('title'):$(v).attr('title'),
				$(v).attr('confirm'),
				{
					"ok":function(e,h){
						$(h).unbind(e.type);
						$.each($(h).data('ferv-events'),function(k,v){$(h).bind(v[0],v[1]);});
						$(h).trigger(e.type);
						wp_octoms.confirm();
					},
					"cancel":function(e,h){
					}
				},
				e,
				v
			);
			return false;
		};
		
		$.each($('[confirm]'),function(_k,_v){
			if((typeof $(_v).data('events') != 'undefined'||typeof $(_v).attr('onclick') != 'undefined'||typeof $(_v).attr('onsubmit') != 'undefined') && typeof $(_v).data('ferv-events') == 'undefined')
			{
				var data = [];
				var used = 'click';
				if(typeof $(_v).data('events') != 'undefined')
				{
					$.each($(_v).data('events'),function(k,v){
						if( k == 'click' || k == 'submit')
						{
							$.each(v,function(e_k,e_v){
								data[e_k] = [k,e_v['handler']];
							});
							$(_v).unbind(k);
							used = k;
						}
					});
				}
				if(typeof $(_v).attr('onclick') != 'undefined')
				{
					data[data.length] = ['click',new Function($(_v).attr('onclick'))];
					$(_v).removeAttr('onclick');
				}
				if(typeof $(_v).attr('onsubmit') != 'undefined')
				{
					data[data.length] = ['submit',new Function($(_v).attr('onsubmit'))];
					$(_v).removeAttr('onsubmit');
				}
				$(_v).data('ferv-events',data);
				$(_v).bind(used,handler);
			}
		});

		return wp_octoms;
	},
	help:function(){
		if($('help').length > 0 && $('.help-button').length > 0)
		{
			var help = $('help');
			$('.help-button').css('display','block').click(function(e){
				wp_octoms.box(
					(typeof help.attr('title')=='undefined')?(typeof help.data('title')=='undefined'?'WP-OctoMS Help':help.data('title')):help.attr('title'),
					help.html(),
					{
						"Ok":function(e,h){}
					},
					e,
					help
				);
			});
		}
		return wp_octoms;
	}
 };
wp_octoms.init();